package org.ring.common.extension;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @since 2024-10-30 19:15
 */
public class Extensions {

    private static Map<Class<?>, ExtensionLoader<?>> loaderMap = new ConcurrentHashMap<>();

    public static <T> ExtensionLoader<T> getExtensionLoader(Class<T> type) {
        if (type == null) {
            throw new IllegalArgumentException("Extension type is null");
        }
        if (!type.isInterface()) {
            throw new IllegalArgumentException("Extension type (" + type + ") is not an interface!");
        }
        ExtensionLoader loader = loaderMap.get(type);
        if (loader == null) {
            loader = new ExtensionLoader(type);
            loaderMap.put(type, loader);
        }
        return loader;
    }

}
